package com.ureport.test.model;

import com.bstek.ureport.export.ExportManager;
import com.ureport.test.test.DataSourceBean;
import com.ureport.test.utils.ExportUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author 尚智江
 * @description
 * @CreateDate 2023/12/1 10:02
 */

@RestController
public class Controller {


    @Autowired
    ExportManager exportManager;
    @Autowired
    DataSourceBean dataSourceBean;



    public Map<String, Object> test() {

        Map<String,Object> map1 = new HashMap<String, Object>();
        map1.put("name","张三");
        map1.put("identityCode",map1.get("name"));
        map1.put("identityIssueDate",map1.get("name"));
        map1.put("firstPerson",map1.get("name"));
        map1.put("othPersonCount",map1.get("name"));
        map1.put("agentCompanyName",map1.get("name"));
        map1.put("applyReason",map1.get("name"));
        map1.put("dateStr",map1.get("name"));
        System.out.println(map1);
        dataSourceBean.loadPdf(null, null, map1);

        return map1;
    }


    @GetMapping("/a")
    public String a(){
        return "aaaa";
    }


    @GetMapping("export")
    public void export(HttpServletResponse response) throws Exception {
        Map<String,Object> map1 = new HashMap<String, Object>();
        map1.put("identityCode","name");
        map1.put("identityIssueDate","name");
        map1.put("firstPerson","name");
        map1.put("othPersonCount","name");
        map1.put("agentCompanyName","name");
        map1.put("applyReason","name");
        map1.put("dateStr","name");
        String fileName = "身元保证书.pdf";
        Map<String, Object> map = dataSourceBean.loadPdf(null, null, map1).get(0);
        String source = "file:身元2.0.ureport.xml";
        ExportUtils.exportPdf(exportManager,source,map,fileName,response);
    }

    @GetMapping("/excel")
    public void exportExcel(HttpServletResponse response) throws Exception {
        String fileName = "身元保证书.xls";
        Map<String, Object> dataMap = dataSourceBean.loadPdf(null, null, null).get(0);
        ExportUtils.exportExcel(exportManager,"file:身元2.0.ureport.xml",dataMap,fileName,response);

    }
}
